package reflectionAndAnnotation.reflection;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

/**
 * @author zxl
 * @version 1.0
 * @date 2021/10/24 16:09
 */
public class PropertiesTest {
    public static void main(String[] args) throws IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        //获得配置文件的内容
        Properties properties = new Properties();
        FileReader fileReader = new FileReader("properies");
        properties.load(fileReader);
        fileReader.close();

        String className = properties.getProperty("className");
        String method = properties.getProperty("Method");
        System.out.println(className);
        System.out.println(method);

        //反射
        Class<?> aClass = Class.forName(className);
        Constructor<?> constructor = aClass.getConstructor();
        Object o = constructor.newInstance();
        Method declaredMethod = aClass.getDeclaredMethod(method, String.class);
        declaredMethod.invoke(o,"哈哈");

    }
}
